var HttpCode = require('./httpcode.js');

/**
 * Definition of SystemDesignError
 */
var SystemDesignError = function (message) {
    Error.call(this);
    Error.captureStackTrace(this, arguments.callee);

    this.name = "SystemDesignError";
    this.message = message;
    this.httpCode = HttpCode.HTTP_SERVICE_UNAVAILABLE;
};

SystemDesignError.prototype.__proto__ = Error.prototype;

/**
 * Definition of ConfigError
 * Caused by invalid configuration
 */
var ConfigError = function (configItemName, message) {
    Error.call(this);
    Error.captureStackTrace(this, arguments.callee);

    this.name = "ConfigError";
    this.message = "Invalid configuration [ " + configItemName + " ]!";
    if (message) this.message += ' ' + message;
    this.httpCode = HttpCode.HTTP_SERVICE_UNAVAILABLE;
};

ConfigError.prototype.__proto__ = Error.prototype;

/**
 * Definition of UsageError
 * Caused by developer usage error
 */
var UsageError = function (message) {
    Error.call(this);
    Error.captureStackTrace(this, arguments.callee);

    this.name = "UsageError";
    this.message = "Invalid usage!";
    if (message) this.message += ' ' + message;
    this.httpCode = HttpCode.HTTP_INTERNAL_SERVER_ERROR;
};

UsageError.prototype.__proto__ = Error.prototype;

/**
 * Definition of NotFoundError
 */
var NotFoundError = function () {
    Error.call(this);
    Error.captureStackTrace(this, arguments.callee);

    this.name = "NotFoundError";
    this.message = "Not found!";
    this.httpCode = HttpCode.HTTP_NOT_FOUND;
};

NotFoundError.prototype.__proto__ = Error.prototype;

/**
 * Definition of ArgumentError
 */
var ArgumentError = function (name, message) {
    Error.call(this);
    Error.captureStackTrace(this, arguments.callee);

    this.name = "ArgumentError";
    this.message = "Invalid argument [" + name + "]!";
    if (message) this.message += ' ' + message;
    this.httpCode = HttpCode.HTTP_BAD_REQUEST;
};

ArgumentError.prototype.__proto__ = Error.prototype;

/**
 * Definition of DbOperationError
 */
var DbOperationError = function (err) {
    Error.call(this);
    Error.captureStackTrace(this, arguments.callee);

    this.name = "DbOperationError";
    this.message = err ? (err.message || err.toString()) : "Database operation error occurred!";
    this.httpCode = HttpCode.HTTP_INTERNAL_SERVER_ERROR;
};

DbOperationError.prototype.__proto__ = Error.prototype;

exports.SystemDesignError = SystemDesignError;
exports.ConfigError = ConfigError;
exports.ArgumentError = ArgumentError;
exports.DbOperationError = DbOperationError;
exports.NotFoundError = NotFoundError;
exports.UsageError = UsageError;

